package org.andes.kownledge.operator.executable;

import java.util.ArrayList;
import java.util.List;

import org.andes.base.Bindings;
import org.andes.base.Unification;
import org.andes.kownledge.operator.Executable;
import org.andes.kownledge.operator.Variable;
import org.andes.kownledge.operator.func.Func;
import org.andes.sgg.st;

public class Bind extends Executable{
	private Variable var;
	private Func func;
	
	
	public Bind(Variable var2, Func func2) {
		this.var=var2;
		this.func=func2;
	}


	public Variable getVar() {
		return var;
	}


	public void setVar(Variable var) {
		this.var = var;
	}


	public Func getFunc() {
		return func;
	}


	public void setFunc(Func func) {
		this.func = func;
	}


	//	(defun execute-bind (E State)
//	  "Implements the (bind <variable> <function>) condition of operators.
//	   Returns zero or one state."
//	  (let* ((Variable (second E))
//	         (New-Value (eval (subst-bindings-quoted (St-Bindings State) 
//							 (third E))))
//		 (new-bindings (unify Variable New-Value (St-Bindings State))))
//	    (when new-bindings (setf (st-bindings state) new-bindings) (list State))))
	@Override
	public List<st> exec(st State) {
		
		Variable var=getVar();
		Func func=getFunc();
		Variable newV=(Variable) func.doFunc();
		Bindings bindings=Unification.unify(var, newV, State.getBindings());		
		if(bindings!=null){
			State.setBindings(bindings);
		}
		List<st> result=new ArrayList<st>();
		return result;
	}

}
